package com.wushijia.highconcurrency;

public class DaemonTest {

  public static class DaemonThread extends Thread {

    @Override
    public void run() {
      while (true) {
        System.out.println("I am running");
        try {
          Thread.sleep(1000);
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
      }
    }
  }

  public static void main(String[] args) throws InterruptedException {
    DaemonThread thread = new DaemonThread();
    //只有守护线程时，虚拟机会退出，否则下面的线程会一直执行
    thread.setDaemon(true);
    thread.start();
    Thread.sleep(4000);
  }
}
